﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using E.Model;
using E.DAL;

namespace E.BLL
{
    public class QuestionBLL
    {
        private QuestionDAL dal;

        public QuestionBLL()
        {
            dal = new QuestionDAL();
        }

        /// <summary>
        /// 获取题目类型列表
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, string> GetQuestionCategoryList()
        {
            return dal.GetQuestionCategoryList();
        }

        /// <summary>
        /// 获取题目列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public QuestionListModel GetQuestionList(SearchQuestionModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetQuestionList(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取内训题目列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public QuestionListModel GetInternalQuestionList(SearchQuestionModel searchModel, int pageSize, int pageIndex)
        {
            return dal.GetInternalQuestionList(searchModel, pageSize, pageIndex);
        }

        /// <summary>
        /// 获取题目信息（包括选项列表）
        /// </summary>
        /// <param name="questionid"></param>
        /// <returns></returns>
        public QuestionModel GetQuestionInfo(int questionid)
        {
            return dal.GetQuestionInfo(questionid);
        }

        /// <summary>
        /// 获取题目详细信息
        /// </summary>
        /// <param name="questionid"></param>
        /// <returns></returns>
        public QuestionModel GetQuestionDetailInfo(int questionid)
        {
            return dal.GetQuestionDetailInfo(questionid);
        }

        /// <summary>
        /// 获取选项列表
        /// </summary>
        /// <param name="questionid"></param>
        /// <returns></returns>
        public IList<QuestionOptionModel> GetOptionList(int questionid)
        {
            return dal.GetOptionList(questionid);
        }

        /// <summary>
        /// 添加题目
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddQuestion(QuestionModel model)
        {
            return dal.AddQuestion(model);
        }

        /// <summary>
        /// 修改题目
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateQuestion(QuestionModel model)
        {
            return dal.UpdateQuestion(model);
        }

        /// <summary>
        /// 删除题目
        /// </summary>
        /// <param name="questionid"></param>
        /// <returns></returns>
        public int DelQuestion(string[] questionid)
        {
            return dal.DelQuestion(questionid);
        }

        /// <summary>
        /// 根据类别获取题目ID
        /// </summary>
        /// <param name="categoryid"></param>
        /// <param name="areaid"></param>
        /// <param name="courseid"></param>
        /// <param name="isRequired">0为普通，1为必选</param>
        /// <returns></returns>
        public IList<int> GetQuestionIDByCategory(int categoryid, int areaid, int courseid, int isRequired)
        {
            return dal.GetQuestionIDByCategory(categoryid, areaid, courseid, isRequired);
        }

        /// <summary>
        /// 根据课程获取题目ID
        /// </summary>
        /// <param name="areaid"></param>
        /// <param name="courseid"></param>
        /// <returns></returns>
        public IList<int> GetQuestionIDByCourse(int areaid, int courseid)
        {
            return dal.GetQuestionIDByCourse(areaid, courseid);
        }

        /// <summary>
        /// 根据类别获取题目ID(返回多列)
        /// </summary>
        /// <param name="categoryid"></param>
        /// <param name="areaid"></param>
        /// <param name="courseid"></param>
        /// <param name="isRequired">0为普通，1为必选</param>
        /// <returns></returns>
        public IList<QuestionModel> GetQuestionIDByCategory(int categoryid, int areaid, int courseid, int isRequired, bool bIsMultiData)
        {
            return dal.GetQuestionIDByCategory(categoryid, areaid, courseid, isRequired, true);
        }

        /// <summary>
        /// 获取考试设置
        /// </summary>
        /// <param name="examid"></param>
        /// <returns></returns>
        public Dictionary<int, int> GetExamSetting(int examid)
        {
            return dal.GetExamSetting(examid);
        }

        /// <summary>
        /// 获取题目详细信息及选项列表
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public IList<QuestionModel> GetQuestionDetailInfoList(SearchQuestionModel searchModel)
        {
            return dal.GetQuestionDetailInfoList(searchModel);
        }
        

        /// <summary>
        /// 获取题目详细信息及选项列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList<QuestionModel> GetQuestionDetailInfoList(IList<int> id)
        {
            return dal.GetQuestionDetailInfoList(id);
        }

        /// <summary>
        /// 获取题目详细信息及选项列表，如果该用户未参加过考试，则插入考试信息，如果已经参加过却没有提交，则返回原先考试ID
        /// </summary>
        /// <param name="testModel"></param>
        /// <returns></returns>
        public IList<QuestionModel> GetQuestionDetailInfoListByParms(TestModel testModel)
        {
            return dal.GetQuestionDetailInfoListByParms(testModel);
        }

        /// <summary>
        /// 获取题目详细信息及选项列表
        /// </summary>
        /// <param name="testModel"></param>
        /// <returns></returns>
        public IList<QuestionModel> GetQuestionDetailInfoListSelfByParms(TestModel testModel)
        {
            return dal.GetQuestionDetailInfoListSelfByParms(testModel);
        }

        /// <summary>
        /// 获取当前题目类别所设置题目数的总分
        /// </summary>
        /// <param name="categoryid"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public int[] GetCurrentTotalScore(int categoryid, int quantity)
        {
            return dal.GetCurrentTotalScore(categoryid, quantity);
        }

        /// <summary>
        /// 获取试卷信息
        /// </summary>
        /// <param name="testid"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public TestDetailInfoModel GetTestDetailInfo(int testid, int userid)
        {
            return dal.GetTestDetailInfo(testid, userid);
        }

        /// <summary>
        /// 获取某一课程某一类别题目总数
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="categoryid"></param>
        /// <returns></returns>
        public int GetAllQuestionQuantity(int courseid, int categoryid)
        {
            return dal.GetAllQuestionQuantity(courseid, categoryid);
        }

        /// <summary>
        /// 获取某一课程某一类别必选题目总数
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="categoryid"></param>
        /// <returns></returns>
        public int GetAllRequiredQuestionQuantity(int courseid, int categoryid)
        {
            return dal.GetAllRequiredQuestionQuantity(courseid, categoryid);
        }

        /// <summary>
        /// 更新主观题分数和考试的总分数
        /// </summary>
        /// <param name="courseid"></param>
        /// <param name="categoryid"></param>
        /// <returns></returns>
        public void UpdateSubjectiveScoreAndTotalScore(int testLogId, TestDetailInfoModel testDetailInfoModel)
        {
            dal.UpdateSubjectiveScoreAndTotalScore(testLogId,testDetailInfoModel);
        }

        /// <summary>
        /// 获得所有试题类型
        /// </summary>
        /// <returns></returns>
        public IList<QuestionCategoryModel> GetAllQuestionCategoryModel()
        {
            return dal.GetAllQuestionCategoryModel();
        }

        public void UpdateQuestionCategoryDefaultScore(QuestionCategoryModel model)
        {
            dal.UpdateQuestionCategoryDefaultScore(model);
        }
    }
}
